package com.kateba.android.blueinput;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.kateba.android.hid.KBLayout;
import com.kateba.android.utils.TeksoftAdView;
import com.kateba.android.utils.Utils;
import com.teksoftco.android.utils.ImageBut;


public class GUIBlueinput extends Activity
  implements View.OnClickListener, AdapterView.OnItemClickListener, AdapterView.OnItemSelectedListener
{
  public static final int REQUEST_ENABLE_BT = 3;
  public static final int idButRegister = 509;
  public static final int idCheckDebug = 511;
  public static final int idCheckHints = 512;
  public static final int idCheckKB = 506;
  public static final int idCheckMouse = 505;
  public static final int idEditRegStatus = 508;
  public static final int idEditSerialKey = 507;
  public static final int idImgBluetooth = 106;
  public static final int idImgCapsLock = 104;
  public static final int idImgNumLock = 105;
  public static final int idLV1FirstItem = 1001;
  public static final int idLV2FirstItem = 2001;
  public static final int idLVAvailable = 202;
  public static final int idLVConnected = 107;
  public static final int idMenuTab1Help = 102;
  public static final int idMenuTab1Minimize = 103;
  public static final int idMenuTab2Help = 204;
  public static final int idMenuTab2Search = 203;
  public static final int idMenuTab4Help = 402;
  public static final int idMenuTab5EULA = 503;
  public static final int idMenuTab5FB = 514;
  public static final int idMenuTab5Help = 504;
  public static final int idMenuTab5Share = 515;
  public static final int idMenuTab5Website = 502;
  public static final int idSpinLayouts = 513;
  public static final int idTab = 2;
  public static final int idTab1 = 101;
  public static final int idTab2 = 201;
  public static final int idTab3 = 301;
  public static final int idTab4 = 401;
  public static final int idTab5 = 501;
  final String LOG_TAG = "BlueInput::GUI";
  public Logic logic = new Logic(this);
  public TeksoftAdView m_AboutAd;
  public RelativeLayout m_GlobalPanel;
  Spinner m_LayoutSpin;
  public TeksoftAdView[] m_SmallAd = new TeksoftAdView[4];
  public View[] m_Tab = new View[5];
  ListView m_lv1Connected;
  ListView m_lv2Available;
  int m_nCurrentTab = 1;
  com.kateba.android.utils.DrawView m_panelGFX;
  public ProgressDialog m_progDlg;

  private boolean ApplyCommand(View paramView, int paramInt1, int paramInt2)
  {
    Singleton.getInstance().Debug("BlueInput::GUI", "ApplyCommand:" + paramInt1 + " Param:" + paramInt2);
    int i = Singleton.getInstance().m_BTInterf.BTCount;
    if ((paramInt1 >= 1001) && (paramInt1 < i + 1001))
    {
      int k = this.logic.BTDevId2Index(paramInt1 - 1001);
      this.logic.ListItemDisconnect(k);
    }
    int j = 0;
    if ((paramInt1 >= 2001) && (paramInt1 < i + 2001))
    {
      j = this.logic.BTDevId2Index(paramInt1 - 2001);
      if (this.logic.CheckBluetooth())
      {
        if (!Singleton.getInstance().m_BTInterf.BTDevs[j].isConnected())
//          break label346;
        ChangeTab(0);
        this.logic.MessageToast(2131034166);
      }
    }
    switch (paramInt1)
    {
    case 507:
    default:
    case 101:
    case 201:
    case 301:
    case 401:
    case 501:
    case 102:
    case 103:
    case 203:
    case 204:
    case 402:
    case 506:
    case 511:
    case 512:
    case 505:
    case 513:
    case 502:
    case 503:
    case 504:
    case 515:
    case 514:
    case 509:
    }
    while (true)
    {
     // return true;
      //label346:
    	  switch (this.logic.ListItemConnect(j))
      {
      default:
        break;
      case -4:
        this.logic.MessageToast(2131034175);
        break;
      case -1:
        this.logic.MessageToast(2131034165);
        break;
      case -3:
      case -2:
        this.logic.MessageToast(getResources().getString(2131034167) + " " + Singleton.getInstance().m_BTInterf.BTDevs[j].m_szName);
        break;
      case 0:
        ChangeTab(0);
        this.logic.MessageToast(getResources().getString(2131034168) + " " + Singleton.getInstance().m_BTInterf.BTDevs[j].m_szName);
      //  break;
        ChangeTab(0);
        continue;
        ChangeTab(1);
        continue;
        ChangeTab(2);
        continue;
        ChangeTab(3);
        continue;
        ChangeTab(4);
        continue;
        this.logic.MessageBox(null, getResources().getString(2131034121));
        continue;
        this.logic.StartActivity(1);
        continue;
        if (!this.logic.CheckBluetooth())
          continue;
        this.logic.startDiscoverBluetoothDevices();
        continue;
        this.logic.MessageBox(null, getResources().getString(2131034122));
        continue;
        this.logic.MessageBox(null, getResources().getString(2131034123));
        continue;
        Singleton.getInstance().m_sett.setKBSounds(((CheckBox)paramView).isChecked());
        continue;
        Singleton.getInstance().m_sett.setDebug(((CheckBox)paramView).isChecked());
        continue;
        Singleton.getInstance().m_sett.setHints(((CheckBox)paramView).isChecked());
        continue;
        Singleton.getInstance().m_sett.setMouseSounds(((CheckBox)paramView).isChecked());
        continue;
        if (Singleton.getInstance().m_sett.getLayoutID() == paramInt2)
          continue;
        Singleton.getInstance().m_sett.setLayoutID(paramInt2);
        KBLayout.LoadLayout(this, paramInt2);
        continue;
        this.logic.StartActivity(2);
        continue;
        this.logic.MessageBox(null, Utils.AssetTextFileToString(this, "eula.txt"));
        continue;
        this.logic.MessageBox(null, getResources().getString(2131034124));
        continue;
        this.logic.StartActivity(3);
        continue;
        this.logic.StartActivity(4);
        continue;
        EditText localEditText = (EditText)findViewById(507);
        TextView localTextView = (TextView)findViewById(508);
        Button localButton = (Button)findViewById(509);
        String str = localEditText.getText().toString();
        boolean bool = Singleton.getInstance().m_regObj.CheckUserInputKey(str);
        Singleton.getInstance().m_sett.setRegStatus(bool);
        Singleton.getInstance().Debug("BlueInput::GUI", "CMD(idButRegister):" + str + " res:" + bool);
        if (bool)
        {
          this.logic.MessageBox(null, getResources().getString(2131034160));
          localButton.setEnabled(false);
          localEditText.setEnabled(false);
          localTextView.setText(getResources().getString(2131034148));
          localTextView.setTextColor(Singleton.clrText);
          continue;
        }
        this.logic.MessageBox(null, getResources().getString(2131034161));
      }
    }
  }

  void ChangeTab(int paramInt)
  {
    int i;
    if ((this.m_Tab != null) && (paramInt >= 0) && (paramInt < this.m_Tab.length))
    {
      this.m_nCurrentTab = paramInt;
      i = 0;
      if (i < 5)
//        break label181;
      RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-1, -1);
      localLayoutParams1.addRule(3, 2);
      localLayoutParams1.addRule(14);
      this.m_GlobalPanel.addView(this.m_Tab[paramInt], localLayoutParams1);
      if ((!Singleton.getInstance().m_sett.getRegStatus()) && (paramInt != 4) && (!this.m_SmallAd[paramInt].IsDismissed()))
      {
        this.m_GlobalPanel.removeView(this.m_SmallAd[paramInt]);
        RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams2.addRule(12);
        this.m_GlobalPanel.addView(this.m_SmallAd[paramInt], localLayoutParams2);
      }
      switch (paramInt)
      {
      case 1:
      default:
      case 0:
      case 2:
      case 3:
      }
    }
    while (true)
    {
      return;
      label181: this.m_GlobalPanel.removeView(this.m_Tab[i]);
      i++;
      break;
      this.logic.PopulateBluetooth();
      continue;
      this.m_panelGFX.Clear();
      if (!Singleton.getInstance().m_sett.getHints())
        continue;
      this.logic.MessageToast(2131034114);
      continue;
      this.m_LayoutSpin.setSelection(Singleton.getInstance().m_sett.getLayoutID());
    }
  }

  public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    switch (paramInt1)
    {
    default:
    case 3:
    }
//    while (true)
//    {
////      return;
//      if (paramInt2 != -1)
//      {
//        this.logic.MessageToast(2131034173);
//        continue;
//      }
//    }
  }

  public void onClick(View paramView)
  {
    ApplyCommand(paramView, paramView.getId(), 0);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    Singleton.getInstance().m_guiInst = this;
    if (Integer.parseInt(Build.VERSION.SDK) < 7)
    {
      this.logic.MessageToast(2131034172);
      finish();
    }
    requestWindowFeature(1);
    if (Singleton.getInstance().m_BTInterf.m_BluetoothAdapter == null)
    {
      this.logic.MessageToast(2131034127);
      finish();
      return;
    }
    Singleton.getInstance().Debug("BlueInput::GUI", "onCreate: register filters");
    IntentFilter localIntentFilter1 = new IntentFilter("android.bluetooth.device.action.FOUND");
    registerReceiver(Singleton.getInstance().m_BTInterf.mReceiver, localIntentFilter1);
    IntentFilter localIntentFilter2 = new IntentFilter("android.bluetooth.adapter.action.DISCOVERY_FINISHED");
    registerReceiver(Singleton.getInstance().m_BTInterf.mReceiver, localIntentFilter2);
    KBLayout.LoadLayout(this, Singleton.getInstance().m_sett.getLayoutID());
    Singleton.getInstance().m_sett.setRegStatus(Singleton.getInstance().m_regObj.IsRegistered());
    int i = Singleton.getInstance().applySCRDensity(this, 6);
    RelativeLayout localRelativeLayout1 = new RelativeLayout(this);
    this.m_GlobalPanel = localRelativeLayout1;
    this.m_GlobalPanel.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
    this.m_GlobalPanel.setBackgroundColor(Singleton.clrBackgroundPanel);
    setContentView(this.m_GlobalPanel);
    int[] arrayOfInt1 = new int[5];
    arrayOfInt1[0] = 2131034116;
    arrayOfInt1[1] = 2131034117;
    arrayOfInt1[2] = 2131034118;
    arrayOfInt1[3] = 2131034119;
    arrayOfInt1[4] = 2131034120;
    int[] arrayOfInt2 = new int[5];
    arrayOfInt2[0] = 2130837527;
    arrayOfInt2[1] = 2130837528;
    arrayOfInt2[2] = 2130837531;
    arrayOfInt2[3] = 2130837529;
    arrayOfInt2[4] = 2130837530;
    int[] arrayOfInt3 = new int[5];
    arrayOfInt3[0] = 101;
    arrayOfInt3[1] = 201;
    arrayOfInt3[2] = 301;
    arrayOfInt3[3] = 401;
    arrayOfInt3[4] = 501;
    LinearLayout localLinearLayout = new LinearLayout(this);
    localLinearLayout.setBackgroundColor(Singleton.clrBackgroundPanel);
    localLinearLayout.setId(2);
    localLinearLayout.setOrientation(0);
    localLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
    localLinearLayout.setPadding(i, i, i, i);
    int j = 0;
    label411: if (j >= 5)
    {
      RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-1, -2);
      localLayoutParams1.addRule(10);
      localLayoutParams1.addRule(14);
      this.m_GlobalPanel.addView(localLinearLayout, localLayoutParams1);
      View[] arrayOfView1 = this.m_Tab;
      GUITab1 localGUITab11 = new GUITab1(this);
      arrayOfView1[0] = localGUITab11;
      View[] arrayOfView2 = this.m_Tab;
      GUITab2 localGUITab21 = new GUITab2(this);
      arrayOfView2[1] = localGUITab21;
      View[] arrayOfView3 = this.m_Tab;
      GUITab3 localGUITab3 = new GUITab3(this);
      arrayOfView3[2] = localGUITab3;
      View[] arrayOfView4 = this.m_Tab;
      GUITab4 localGUITab41 = new GUITab4(this);
      arrayOfView4[3] = localGUITab41;
      View[] arrayOfView5 = this.m_Tab;
      GUITab5 localGUITab51 = new GUITab5(this);
      arrayOfView5[4] = localGUITab51;
      GUITab1 localGUITab12 = (GUITab1)this.m_Tab[0];
      this.m_lv1Connected = localGUITab12.m_lvConnected;
      this.m_lv1Connected.setId(107);
      this.logic.PopulateLV1Connected();
      localGUITab12.m_IB[0].setId(102);
      localGUITab12.m_IB[1].setId(103);
      localGUITab12.m_IB[2].setId(106);
      localGUITab12.m_IB[3].setId(104);
      localGUITab12.m_IB[4].setId(105);
      GUITab2 localGUITab22 = (GUITab2)this.m_Tab[1];
      this.m_lv2Available = localGUITab22.m_lvAvailable;
      this.m_lv2Available.setId(202);
      this.logic.PopulateLV2Available();
      localGUITab22.m_IB[0].setId(204);
      localGUITab22.m_IB[1].setId(203);
      this.m_panelGFX = ((GUITab3)this.m_Tab[2]).m_panelGFX;
      GUITab4 localGUITab42 = (GUITab4)this.m_Tab[3];
      localGUITab42.m_IB[0].setId(402);
      this.m_LayoutSpin = localGUITab42.m_LayoutSpin;
      GUITab5 localGUITab52 = (GUITab5)this.m_Tab[4];
      localGUITab52.m_IB[0].setId(504);
      localGUITab52.m_IB[1].setId(502);
      localGUITab52.m_IB[2].setId(503);
      localGUITab52.m_IB[3].setId(515);
      localGUITab52.m_IB[4].setId(514);
      TeksoftAdView localTeksoftAdView1 = new TeksoftAdView(this);
      this.m_AboutAd = localTeksoftAdView1;
      this.m_AboutAd.SetStats(true);
      this.m_AboutAd.SetBackground(-1);
      this.m_AboutAd.AddAd(Utils.AssetTextFileToString(this, "p28_normal.html"), true);
      this.m_AboutAd.AddAd(Utils.AssetTextFileToString(this, "p30_normal.html"), false);
      this.m_AboutAd.AddOnlineAd("http://www.teksoftco.com/mobileads.php?&param=mobilenormal&pid=24&version=2.0.209", false);
      this.m_AboutAd.AddOnlineAd("http://www.teksoftco.com/mobileads.php?&param=mobilenormal&pid=24&version=2.0.209", false);
      this.m_AboutAd.SetRotateAd(10);
      localGUITab52.panelVScroll.addView(this.m_AboutAd);
      if (Singleton.getInstance().m_sett.getRegStatus());
    }
    for (int k = 0; ; k++)
    {
      if (k >= 4)
      {
        ChangeTab(this.m_nCurrentTab);
        break;
        ImageBut localImageBut = new ImageBut(this, arrayOfInt2[j], false);
        localImageBut.setOnClickListener(this);
        localImageBut.setId(arrayOfInt3[j]);
        TextView localTextView = localImageBut.getTextView();
        localTextView.setText(getResources().getString(arrayOfInt1[j]));
        localTextView.setShadowLayer(i, 0.0F, 0.0F, -1);
        localTextView.setTextColor(Singleton.clrText);
        localTextView.setTextSize(2, 12.0F);
        localTextView.setTypeface(Typeface.DEFAULT, 1);
        RelativeLayout localRelativeLayout2 = new RelativeLayout(this);
        RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams2.addRule(13);
        localRelativeLayout2.addView(localImageBut, localLayoutParams2);
        localLinearLayout.addView(localRelativeLayout2, new LinearLayout.LayoutParams(-1, -1, 1.0F));
        j++;
        break label411;
      }
      TeksoftAdView[] arrayOfTeksoftAdView = this.m_SmallAd;
      TeksoftAdView localTeksoftAdView2 = new TeksoftAdView(this);
      arrayOfTeksoftAdView[k] = localTeksoftAdView2;
      this.m_SmallAd[k].SetStats(true);
      this.m_SmallAd[k].AddAd(Utils.AssetTextFileToString(this, "p28_slim.html"), true);
      this.m_SmallAd[k].AddAd(Utils.AssetTextFileToString(this, "p30_slim.html"), false);
      this.m_SmallAd[k].SetLogo(2130837504, "Ads by Teksoft");
      this.m_SmallAd[k].AddOnlineAd("http://www.teksoftco.com/mobileads.php?&param=mobileslim&pid=24&version=2.0.209", false);
      this.m_SmallAd[k].AddOnlineAd("http://www.teksoftco.com/mobileads.php?&param=mobileslim&pid=24&version=2.0.209", false);
      this.m_SmallAd[k].SetRotateAd(10);
    }
  }

  public void onDestroy()
  {
    super.onDestroy();
    Singleton.getInstance().Debug("BlueInput::GUI", "onDestroy: Called");
    unregisterReceiver(Singleton.getInstance().m_BTInterf.mReceiver);
  }

  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    View localView = null;
    if (paramView != null)
      localView = (View)paramView.getParent();
    if (localView != null)
      ApplyCommand(paramView, localView.getId(), paramInt);
  }

  public void onItemSelected(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    ApplyCommand(paramView, 513, paramInt);
  }

  public void onNothingSelected(AdapterView<?> paramAdapterView)
  {
  }

  public void onPause()
  {
    super.onPause();
    Singleton.getInstance().Debug("BlueInput::GUI", "onPause: Called");
  }

  public void onResume()
  {
    super.onResume();
    Singleton.getInstance().Debug("BlueInput::GUI", "onResume: Called");
  }

  public void onStart()
  {
    super.onStart();
    if (!Singleton.getInstance().m_sett.getRegStatus())
      this.logic.MessageToast(2131034176);
  }
}